package com.bidepan.spring6.resource;

import org.springframework.core.io.FileSystemResource;

import java.io.InputStream;

//访问系统中的资源
public class FileSystemResourceDemo {
    public static void loadFileSystemResources(String path){
        //创建对象
        FileSystemResource resource = new FileSystemResource(path);
        //资源信息
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());
        //文件内容
        try{
            InputStream in = resource.getInputStream();
            int available = in.available();
            byte[] bytes = new byte[available];
            while(in.read(bytes) != -1){
                System.out.println(new String(bytes));
            }
            in.close();
        }
        catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    public static void main(String[] args){
        loadFileSystemResources("D:\\86151\\javaWeb\\spring6\\myTxt.txt");
        loadFileSystemResources("myTxt.txt");
    }
}
